<template>
  <div>
    <div style="text-align: center">
      <el-avatar
        class="UserAvatar"
        :size="200"
        style="
          font-size: 50px;
          vertical-align: middle;
          background-color: cornflowerblue;
          margin-top: 30px;
        "
      >
        {{ userName }}
      </el-avatar>
      <br />
      <br />
    </div>
    <div class="userinformation">
      <el-descriptions :column="1" border>
        <el-descriptions-item label="用户名" v-model="userName"
          ><p class="usermessage">
            {{ userName }}
          </p></el-descriptions-item
        >
        <el-descriptions-item
          label="邮箱号"
          v-model="userEmail"
          class="usermessage"
          ><p class="usermessage">{{ userEmail }}</p></el-descriptions-item
        >
        <el-descriptions-item
          label="性别"
          v-model="userGender"
          class="usermessage"
        >
          <span v-if="userGender == true"> 男 </span>
          <span v-if="userGender == false"> 女 </span>
        </el-descriptions-item>
        <el-descriptions-item
          label="特长"
          v-model="userSpecialty"
          class="usermessage"
          ><p class="usermessage">{{ userSpecialty }}</p></el-descriptions-item
        >
        <el-descriptions-item
          label="个人介绍"
          v-model="userIntroduction"
          class="usermessage"
          ><p class="usermessage">
            {{ userIntroduction }}
          </p></el-descriptions-item
        >
      </el-descriptions>
      <br />
      <br />
      <div style="text-align: center">
        <el-button
          color="#626aef"
          :dark="isDark"
          type="large"
          @click="editInformation"
          >编辑个人信息</el-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  name: "UserInformationSetting",
  data() {
    return {
      userId: "",
      userName: "",
      userEmail: "",
      userGender: "",
      userSpecialty: "",
      userIntroduction: "",
    };
  },
  created() {
    this.findUserByToken();
  },
  methods: {
    findUserByToken() {
      request
        .get("/secure/getUserInfo")
        .then((res) => {
          if (res.code == 200) {
            this.userId = res.data.id;
            this.userName = res.data.username;
            this.userEmail = res.data.email;
            this.userGender = res.data.gender;
            this.userSpecialty = res.data.specialty;
            this.userIntroduction = res.data.introduction;
          } else {
            console.log("获取信息失败");
          }
        })
        .catch((err) => {
          console.log("获取信息失败");
        });
    },
    editInformation() {
      this.$router.push(`/usereditinformation`);
    },
  },
};
</script>

<style scoped>
.usermessage {
  width: 20em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.userinformation {
  margin-left: 300px;
  margin-right: 300px;
}
</style>
